<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>${title}</title>
<%@include file="/WEB-INF/templates/common/common.jsp"%>
<%-- <link rel="stylesheet" href="${basePath}/static/page/css/pagination.css" />
<link rel="stylesheet" href="${basePath}/static/page/css/reset.css" />
<script type="text/javascript" src="${basePath}/static/page/js/jquery.pagination.js"></script>
 --%>
<script type="text/javascript" src="${basePath}/static/page/js/jqPaginator.js"></script>
<script  type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
<script  type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
<link href="${basePath}/static/layer/layer_style.css" rel="stylesheet" type="text/css">
</head>
<body>

</head>
<body>
 <!--头部-->
 <%@include file="/WEB-INF/templates/common/header.jsp"%>

<!------导航条-->
 <%@include file="/WEB-INF/templates/common/navigation.jsp"%>
<div class="list_main lay_out">
 <div class="list_DH">
  <!--打印模块导航栏-->
 <%@include file="/WEB-INF/templates/common/printnav.jsp"%>
 </div>
 <div class="list_NR">
  <div class="loc">
   <h3>打印审批</h3>

  </div>
  <div class="list_con_table"> 
   <div class="search_table">
    <ul>
    <li class="Label_1">病案所属人姓名：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="17"  name='patientName' id='patientName' value='' /></li>
    <li class="Label_1">病案所属人身份证：</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="20" name='patientCard' id='patientCard' value='' /></li>
    <li class="Label_1">申请人姓名：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="17"  name='applyName' id='applyName' value='' /></li>
    <li class="Label_1">申请人身份证：</li>
    <li class="Label_2"><input class="input_box" type="text"  maxlength="20" name='applyCard' id='applyCard' value='' /></li>
    <li class="Label_1">诊疗记录标示：&nbsp;</li>
    <li class="Label_2"><input type="text"  maxlength="12"
					class="input_box" id="medicalRecord"/></li>
	 <li style="width:10%"class="Label_1">审核状态：&nbsp;</li>
	 <li style="width:23%" class="Label_2">&nbsp;
     <input type="radio" checked="checked" name='printCheck' id='' value='1' />未审核
     <input type="radio"   name='printCheck' id='' value='2' />已审核
       <input type="radio"  name='printCheck' id='' value='3' />拒批
    </li> 
    <li class="Label_1">申请时间：&nbsp;<span class="Label_6">*</span></li>
     <li class="Label_2" style="width:400px;text-align:left">
     <input style="width:175px;margin-left:5px" class="input_box" id="timeStart" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text"  name=''  value='' /> 
     - <input style="width:175px" class="input_box" id="timeEnd" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text"  name=''  value='' />
     </li>
    <li class="Label_5">
     <a onclick="queryApplyCheck(0,10)">查询</a>
    </li>
    </ul>
   </div>
  </div>
 <!--  <style>
  .table td{width:116px}
  </style> -->
 <table class="Search_tableList" cellpadding="0" cellspacing="0">  
      <tr>
      <td class="tdLabel_4" style="width:10px"><input onchange="checkAll(this)" type="checkbox" name="checkAll"></td>
      <td class="tdLabel_4">序号</td>
      <td class="tdLabel_4">姓名</td>
      <td class="tdLabel_4">身份证号</td>
      <td class="tdLabel_4">诊疗标示</td>
      <td class="tdLabel_4">申请时间</td>
      <td class="tdLabel_4">审批状态</td>
      <td class="tdLabel_4">申请原因</td>
      <td class="tdLabel_4">操作</td>
      </tr>
      <tbody id="tbody">

      </tbody>
      <tfoot><tr><td colspan="9"><a  style="cursor: pointer;background: #039b8e;border-radius:5px;width:78px; height: 32px;float:left;color:#fff;line-height:32px;text-align:center;" onclick="checkPrintAll()">批量申请</a></td></tr></tfoot>
     </table>
     <div class="pageList">
       <ul class="pagination clearfix" id="page_plus"></ul>
       <div class="pagination">
            <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
       </div>          
    </div>
 </div>
</div>
<!--页脚部分-->
 <%@include file="/WEB-INF/templates/common/footer.jsp"%>
 <script>
 	$(function(){
 		$("#timeEnd").blur(function(){
 			var timeEnd=$("#timeEnd").val();
 	 		if(timeEnd==null||timeEnd==""){
 	 			
 	 		}
 		});
 	});	
 
 	//查询打印申请信息
 	function queryApplyCheck(pageNo,pageSize){
 		 
 		 var val=$('input:radio[name="printCheck"]:checked').val();
 		 var patientName=$("#patientName").val();
 		 var patientCard=$("#patientCard").val();
 		 if(patientCard!=null && patientCard!=""){
 			 if(!isCardNo(patientCard)){
 				layer.alert("身份证号码格式不正确!", {icon: 0});
 			 }
 		 }
 		
 		 var medicalRecord=$("#medicalRecord").val();
 		 var startTime=$("#timeStart").val();
 		 var endTime=$("#timeEnd").val();
 		 var applyName=$("#applyName").val();
 		 var applyCard=$("#applyCard").val();
 		 if(applyCard!=null && applyCard!=""){
 			 if(!isCardNo(applyCard)){
 				 alert("身份证号码格式不正确!");
 			 }
 		 }
 		var timeStart=$("#timeStart").val();
 		//得到日期值并转化成日期格式，replace(//-/g, "//")是根据验证表达式把日期转化成长日期格式
 		var sDate = new Date(document.getElementById("timeStart").value.replace(/-/g, "/"));
 		var eDate = new Date(document.getElementById("timeEnd").value.replace(/-/g, "/"));
 		if(timeStart==""||timeStart==null){
 			layer.alert("申请时间不能为空!", {icon: 0});
 			$("#timeStart").addClass("input_change");
 			$("#timeStart").focus(function() { 
 			  	$(this).removeClass("input_change");	
 			});
 			return;
 		}else if(eDate!=""||eDate!=null){
 			if(sDate>eDate){
 				layer.alert("结束日期不能小于开始日期!", {icon: 0});
 				$("#timeEnd").addClass("input_change");
 				$("#timeEnd").focus(function() { 
 			  	$(this).removeClass("input_change");	
 			});
 				return;
 			}
 		}
        
 		$.ajax({
 			type:"post",
 			url:"${basePath}/print/queryApplyCheck",
 			data:{patientName:patientName,patientCard:patientCard,startTime:startTime,endTime:endTime,status:val,
 				medicalRecord:medicalRecord,applyName:applyName,applyCard:applyCard,pageNo:pageNo,pageSize:pageSize},
 			success:function(data){
 				// console.log(data) 
 				//alert(data.count);
 			    var count = data.count;
 			    
 			
 
 			  
 				 /* page(pageNo,count); */
 				var applyPrintList=data.applyCheckList;
 				
 				//alert(JSON.stringify(applyPrintList));
 				
 				
 				if(applyPrintList!=null && applyPrintList!=""){
 					  /* 分页 */
 			 		initPage(count,pageSize,pageNo+1);
 					$("#tbody").html("");
 					var html="";
 					for(var i in applyPrintList){
 						var applyPrint=applyPrintList[i];
 						html+="<tr>"+
 						 "<td class='tdLabel_5'><input type='checkbox' value='"+applyPrint.applyPrintDetailId+"' name='checkOne'/></td>"+
 					     "<td class='tdLabel_5'>"+((parseInt(i)+1)+(parseInt(pageNo)*pageSize))+"</td>"+
 					     "<td class='tdLabel_5'>"+applyPrint.patientName+"</td>"+
 					     "<td class='tdLabel_5'>"+applyPrint.patientCard+"</td>"+
 					     "<td class='tdLabel_5' >"+applyPrint.medicalRecord+"</td>"+
 					     "<td class='tdLabel_5'>"+applyPrint.applyDate+"</td>"+
 					     "<td class='tdLabel_5' id='check"+applyPrint.applyPrintDetailId+"'>"+getCheckStatus(applyPrint.checkStatus)+"</td>"+
 					     "<td class='tdLabel_5'>"+getApplyReason(applyPrint.applyReason)+"</td>"+
 					     //"<td class='tdLabel_5' id='status"+applyPrint.applyPrintDetailId+"' checkStatus='"+applyPrint.checkStatus+"'><span id='linkId'>("+applyPrint.checkStatus+"==1?<a id='TC1' onclick='checkApply("+applyPrint.applyPrintDetailId+",2,this)'>批准</a>&nbsp;&nbsp;<a id='TC1'  onclick='checkApply("+applyPrint.applyPrintDetailId+",3,this)'>拒批</a>:"+applyPrint.checkStatus+"==2?'已批准':'已拒批')</span></td>"+
 					    "<td class='tdLabel_5' id='status"+applyPrint.applyPrintDetailId+"' checkStatus='"+applyPrint.checkStatus+"'><span id='linkId'><a id='TC1' onclick='checkApply("+applyPrint.applyPrintDetailId+",2,this)'>批准</a>&nbsp;&nbsp;<a id='TC1'  onclick='checkApply("+applyPrint.applyPrintDetailId+",3,this)'>拒批</a></span></td>"+
 					     "</tr>";
 					}
 					$("#tbody").html(html);
 					 
 				}else{
 					
 					$("#tbody").html("");
 					layer.alert("数据为空!", {icon: 5});
 				}
 			}
 		})
 	}
 	
 	function checkApply(applyPrintDetailId,status,obj){
 		
 		var $this=$(obj);
 		var checkStatus=$this.closest('td').attr("checkStatus");
 		if(checkStatus==2){
 			if(status==2){
 				layer.alert("审批已批准,不需要再次申请!", {icon: 0});
 				return;
 			}
 		}
 		
 		if(checkStatus==3){
 			if(status==3){
 				layer.alert("审批已拒绝,不需要再次拒批!", {icon: 0});
 				return;
 			}
 		}
 		
 	$.ajax({
 			type:"post",
 			url:"${basePath}/print/updateApplyStatus",
 			data:{applyPrintDetailId:applyPrintDetailId,status:status},
 			success:function(data){
 				if(data==1){
 					$("#check"+applyPrintDetailId).html(status==2?"已批准":"拒批");
 					$this.closest('td').attr("checkStatus",checkStatus==2?3:2);
 					if(status==2){
 						$("#linkId").html("").html("已批准");
 						layer.alert("打印申请审批成功!", {icon: 0});
 					}else{
 						$("#linkId").html("").html("已拒批");
 						layer.alert("打印申请被拒绝!", {icon: 0});
 					}
 				}else{
 					layer.alert("审批失败!", {icon: 0});
 				}
 			}
 		}); 
 		
 	}
 	
 	
 	//获取checkbox值
	 function getFormVals(name){
			var arr = [];
			$("input[type='checkbox'][name='"+name+"']:checked").each(function(){
				arr.push($(this).val());	
			});
			return arr.toString();
	}
 	
 	//审批状态
 	function getCheckStatus(status){
 		switch(status) {
 			case 1: 
 				return "未批准";
 			break; 
 			case 2: 
 				return "已批准";
 			break; 
 			default: 
 				return "拒批";
 		}
 	}
 	
 	//申请原因
 	function getApplyReason(status){
 		switch(status) {
 			case 1: 
 				return "医保";
 			break; 
 			case 2: 
 				return "司法";
 			break; 
 			case 3: 
 				return "门规";
 			break; 
 			default: 
 				return "其他";
 		}
 	}
 	
	//批量选中checkbox
 	function checkAll(obj){
 		var $this=$(obj);
 		if($this.is(':checked')){
 			$("input[type='checkbox'][name='checkOne']").each(function(){
 				$(this).prop("checked",true);
			});
 		}else{
 			$("input[type='checkbox'][name='checkOne']").each(function(){
 				$(this).prop("checked",false);
			});
 		}
 	} 
 	
 	//选中
 	function checkPrintAll(){
 		var applyPrinDetailId= getFormVals("checkOne");
 	
 		if(applyPrinDetailId==null || applyPrinDetailId==""){
 			layer.alert("请选择一条数据进行操作!", {icon: 0});
 		}else{
 			$.ajax({
 				type:"post",
 				data:{applyPrintDetailIds:applyPrinDetailId,status:2},
 				url:"${basePath}/print/updateBatchApplyStatus",
 				success:function(data){
 					console.log(data)
 					if(data=="success"){
 						var applyPrinDetails=applyPrinDetailId.split(",");
 						for(var i=0;i<applyPrinDetails.length;i++){
 							$("#check"+applyPrinDetails[i]).html("已批准");
 							$("#status"+applyPrinDetails[i]).attr("checkStatus",2);
 						}
 					}else{
 						
 					}
 				}
 			});
 		}
 	}
 	
 	function page(currentPage,totalCounts){
 		
 		var totalCounts = totalCounts;
 	 		var pageSize =10;
 	 		var totalPages = Math.ceil(totalCounts/pageSize);
 	 		var currentPage = currentPage;
 	 		$("#ston_page_msg").text(totalPages);
 	 		$(".number").keypress(function(event) {  
 	 			 var ev = event.which?event.which:window.event.keyCode;
 	 			  if(ev>=48&&ev<=57){
 	 				return true;  
 	 			  }else if(ev==8 || ev==13 || ev==46){
 	 				return true;  
 	 			  }else{
 	 				return false;
 	 			  } 
 	 		}).focus(function() {  
 	 			this.style.imeMode='disabled';  
 	 		});  
 	 		$("#Pagination").pagination(totalPages,{
 	 		current_page:currentPage,
 	 	  callback: function (page_index,jp) {
 	 	 	 //currentPage=page_index;
 	 		queryApplyCheck(page_index,pageSize);
 	 	  } //PageCallback() 为翻页调用次函数。
 	 	  
 	 	  });
 		}
 	
 	//分页
	function initPage(totalCounts,pageSize,currentPage){
		 var visiblePages = 5;
		 var totalPages =Math.ceil(totalCounts/pageSize);
		 $("#totalPage").html(totalCounts);
         $("#currentPage").html(currentPage+"/"+totalPages);
		 $('#page_plus').jqPaginator({

		        totalCounts: totalCounts,
		        pageSize:pageSize,
		        visiblePages: visiblePages,
		        currentPage: currentPage,

		        first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
		        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
		        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
		        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
		        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
		        onPageChange: function (page,type) {
		        	   
		     	  if(type !='init'){
		     		 queryApplyCheck(page-1,pageSize); 
					} 
					
		        }
		    });

	}	

 </script>
</body>
</html>
